<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--<%@taglib prefix="wetechfn" uri="/WEB-INF/tlds/wetech-functions.tld" %>--%>
<%@taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld" %>
<%@ taglib prefix="shiro" uri="/WEB-INF/tlds/shiros.tld" %>
<c:set var="path" value="${pageContext.request.contextPath}"/>
<!-- Content Header (Page header) -->
<section class="content-header" style="">
    <h1>
        档案审核
        <small>档案审核页面</small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> 主页</a></li>
        <li><a href="#">审核管理</a></li>
        <li class="active">档案审核</li>
    </ol>
</section>

<section class="content">
    <div class="row">
        <%--<ul class="nav nav-tabs">
            <li class="active"><a href="#" onclick="loadHref('#approval/test')">单表列表</a></li>
            <li><a href="#approval/test">单表添加</a></li>
        </ul>--%>
        <div class="col-xs-12">
            <div class="box">
                <!-- /.box-header -->
                <div class="box-body">
                    <p id="toolbar">
                    <form class="form-inline">
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-addon">名称</div>
                                <input type="text" class="form-control" name="comName" id="comName_id"
                                       placeholder="关键字...">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <label class="control-label">审核状态</label>
                                <div class="radio-inline">
                                    <label>
                                        &nbsp;&nbsp;
                                        <input type="radio"  name="status_id" id="status_id" value="0">
                                        全部
                                    </label>
                                </div>
                                <div class="radio-inline">
                                    <label>
                                        <input type="radio"  name="status_id" id="status_id" checked="checked" value="1">
                                        未审
                                    </label>
                                </div>
                                <div class="radio-inline">
                                    <label>
                                        <input type="radio"  name="status_id" id="status_id" value="2">
                                        已审
                                    </label>
                                </div>
                            </div>
                        </div>
                        <button type="button" class="btn btn-primary queryButton">查询</button>
                    </form>
                    <table id="table"></table>
                </div>
                <!-- /.box-body -->
            </div>
            <!-- /.box -->
        </div>

    </div>
    <!-- /.row -->
</section>
<!-- /.content -->

<!-- 部门审核通过-->
<div class="modal fade" id="passModal" tabindex="-1" role="dialog" aria-labelledby="passSmallModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="passSmallModalLabel">审核通过</h4>
            </div>
            <div class="modal-body">
                确定将企业名称为<span class="records"></span> 的通过审核吗?
                <form id="passForm"></form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" form="passForm" class="btn btn-primary" data-action="{type:'submit',form:'#passForm',url:'<%=request.getContextPath()%>/fileCheck/checkStatus',after:'$.myAction.refreshTable'}">确定</button>
            </div>
        </div>
    </div>
</div>

<!-- 部门审核拒绝-->
<div class="modal fade" id="noPassModal" tabindex="-1" role="dialog" aria-labelledby="checkSmallModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="noPassSmallModalLabel">审核驳回</h4>
            </div>
            <div class="modal-body">
                <form id="noPassForm">
                    <input type="hidden" id="no_id" name="id" readonly required>
                    <input type="hidden" id="no_status" name="operateType"  readonly required>
                    确定将企业名称为<span class="records"></span> 的审核驳回?
                    <div class="form-group">
                        <label class="control-label"><span class="asterisk">*</span>驳回原因</label>
                        <textarea autofocus  class="form-control" name="remark" placeholder="驳回原因" minlength="1" required/>
                        <div class="help-block with-errors"></div>
                    </div>
                </form>

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" form="noPassForm" class="btn btn-primary" data-action="{type:'submit',form:'#noPassForm',url:'<%=request.getContextPath()%>/fileCheck/checkStatus',after:'$.myAction.refreshTable'}">确定</button>
            </div>
        </div>
    </div>
</div>

<!-- msgShow modal -->
<div class="modal fade" id="msgShowModal" tabindex="-1" role="dialog" aria-labelledby="msgShowSmallModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="msgSmallModalLabel">驳回原因</h4>
            </div>
            <div class="modal-body">
                <div id="showMsgDiv"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 休眠记录 -->
<div class="modal fade" id="msgDorShowModal" tabindex="-1" role="dialog" aria-labelledby="dorHistoryModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="dorHistoryModalLabel">驳回原因</h4>
            </div>
            <div class="modal-body">
                <div id="dorHistoryDiv"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

<!-- 休眠记录 -->
<div class="modal fade" id="waitDorShowModal" tabindex="-1" role="dialog" aria-labelledby="waitDorHistoryModalLabel">
    <div class="modal-dialog modal-sm" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title" id="waitdorHistoryModalLabel">驳回原因</h4>
            </div>
            <div class="modal-body">
                <div id="waitDorHistoryDiv"></div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>


<script>

    function loadHref(s) {
        $.myAdmin.loadContent(s);
    }

    //查询
    $(document).on('click', ".queryButton",function(){
        $('#table').bootstrapTable('refresh');
    });

    var $table = $('#table');

    $(function () {
        // bootstrap table初始化
        // http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/
        $table.bootstrapTable({
            url: path + '/fileCheck/queryByStatusDepartCheck',
            idField: 'id',
            searchOnEnterKey: true,
            showColumns: false,
            detailView: false,
            //得到查询的参数
            queryParams : function (params) {
                //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
                var temp = {
                    limit: params.limit,                         //页面大小
                    offset: params.offset,   //页码
                    // sort: params.sort,      //排序列名
                    order: params.order, //排位命令（desc，asc）
                    comName: $("#comName_id").val(),
                    fileStatus: $("input[name='status_id']:checked").val()
                };
                return temp;
            },
            columns: [
                {field: 'id', title: 'ID'},
                {field: 'comName', title: '名称'},
                {field: 'businessCode', title: '营业执照编号(身份证号)'},
                {field: 'businessTypeSTR', title: '业务品种'},
                {
                    field: 'comType', title: '类别', formatter: function (value, row, index) {
                        if (value == 1) {
                            return "核心企业"
                        } else if (value == 2) {
                            return "一般企业"
                        } else if (value == 3) {
                            return "个人"
                        }
                    }
                },
                {
                    field: 'status', title: '所处阶段', formatter: function (value, row, index) {

                        if (value == 1) {
                            if(row.msgCount>0){
                                return "<a href='javascript:;' onclick='showMsgDetail("+row.id+")'>待尽调<sup style='color: red'>"+row.msgCount+"</sup></a>";
                            }else{
                                return "待尽调"
                            }
                        } else if (value == 2) {
                            if (row.msgCount > 0) {
                                return "<a href='javascript:;' onclick='showMsgDetail(" + row.id + ")'>待部门审核<sup style='color: red'>" + row.msgCount + "</sup></a>";
                            } else {
                                return "待部门审核"
                            }
                        } else if (value == 3) {
                            if(row.msgCount>0){
                                return "<a href='javascript:;' onclick='showMsgDetail("+row.id+")'>待风控审核<sup style='color: red'>"+row.msgCount+"</sup></a>";
                            }else{
                                return "待风控审核"
                            }
                        } else if (value == 4) {
                            return "待上线"
                        } else if (value == 5) {
                            return "贷后管理"
                        } else if (value == 6) {
                            return "存档"
                        }
                    }
                },
                {
                    field: 'dormant', title: '休眠状态', formatter: function (value, row, index) {
                        if (value == 1) {
                            if(row.dormanyCount>0){
                                return "<a href='javascript:;' onclick='showDorMsgDetail("+row.id+")'>正常<sup style='color: red'>"+row.dormanyCount+"</sup></a>";
                            }else{
                                return "正常"
                            }
                        } else if (value == 2) {
                            if(row.dormanyCount>0){
                                if(row.waitDormanyCount>0){
                                    return "<a href='javascript:;' onclick='showWaitDorMsgDetail("+row.id+")'>待休眠<sub style='color:darkmagenta'>"+row.waitDormanyCount+"</sub></a>";
                                }else{
                                    return "<a href='javascript:;' onclick='showDorMsgDetail("+row.id+")'>待休眠<sup style='color: red'>"+row.dormanyCount+"</sup></a>";
                                }
                            }else{
                                if(row.waitDormanyCount>0){
                                    return "<a href='javascript:;' onclick='showWaitDorMsgDetail("+row.id+")'>待休眠<sub style='color:darkmagenta'>"+row.waitDormanyCount+"</sub></a>";
                                }else{
                                    return "待休眠"
                                }
                            }
                        } else if (value == 3) {
                            return "休眠"
                        } else if (value == 4) {
                            return "待正常"
                        }
                    }
                },
                {field: 'inputTime', title: '录入时间'},
                {field: 'activeTime', title: '激活时间'},
                {field: 'upTime', title: '上线时间'},
                /*{field: 'supportId', title: '担保方信息'},*/
                {
                    field: 'action',
                    title: '操作',
                    halign: 'center',
                    align: 'center',
                    formatter: 'actionFormatter',
                    events: 'actionEvents',
                    clickToSelect: false
                }
            ]
        });
    });
    //参数传递
    function Search() {
        var temp = {
            datetime: $("#nowdate").val()
        };
        return temp;
    }
    // 数据表格展开内容
    function detailFormatter(index, row) {
        var html = [];
        $.each(row, function (key, value) {
            html.push('<p><b>' + key + ':</b> ' + value + '</p>');
        });
        return html.join('');
    }
    function actionFormatter(value, row, index) {
        str= '\
        <button id="detail_id" class="btn btn-info" type="button" >资料审核</button>　\
        ';
        if(row.status==2&&(row.dormant==1 ||row.dormant==3)){
            str+='\
        <button id="pass" class="btn btn-success" type="button" >通过</button>　\
        <button id="noPass" class="btn btn-danger" type="button">驳回</button>　\
        ';
        }
        if(row.dormant==2 ){
            str+='\
        <button id="pass" class="btn btn-success" type="button" >休眠通过</button>　\
        <button id="noPass" class="btn btn-danger" type="button">休眠驳回</button>　\
         ';
        }
        return str;
    }

    window.actionEvents = {
        'click #pass': function (e, value, row, index) {
            $('#passModal').modal('show');
            $('.records').html(row.comName);
            var html = '';
            html += '<input type="hidden" name="id" value="' + row.id + '">';
            if(row.dormant==2 ){
                html += '<input type="hidden" name="operateType" value="12">';
            }else if(row.dormant==4){
                html += '<input type="hidden" name="operateType" value="13">';
            }else{
                html += '<input type="hidden" name="operateType" value="3">';
            }

            $('#passForm').html(html);
        },
        'click #noPass': function (e, value, row, index) {
            $('#noPassModal').modal('show');
            $('.records').html(row.comName);
            var operate="4";
            if(row.dormant==2 ){
                operate="14";
            }else if(row.dormant==4){
                operate="15";
            }
            $('#no_id').val(row.id);
            $('#no_status').val(operate);

        },
        'click #detail_id': function (e, value, row, index) {
            var id = row.id
            $.myAdmin.loadContent('#fileCheck/detail?id='+id+'');
        }
    };

    var setting = {
        view: {
            dblClickExpand: false
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        callback: {
            onClick: onClick
        }
    };

    function showMsgDetail(row){
        $.ajax({
            type : "post",
            url : "/archives/approvalRecordList?id="+row,
            async : false,
            success : function(data){
                if (data.status != 0){
                    alert(data.msg);
                }else {
                    $("#msgShowModal").modal('show');
                    var list = [];
                    list = data.msglist;
                    listlength = list.length;
                    var detailHtml = '<tr><th style="width:200px;">原因</th><th style="width:260px;">时间</th></tr>';
                    for (var i = 0; i < list.length; i++) {
                        var demo = list[i].demo;
                        var operateTime = list[i].operateTime;
                        if(operateTime==""||operateTime==null||operateTime=="null"){
                            operateTime="-";
                        }
                        detailHtml += '<tr>';
                        detailHtml += '<td class="txt_c" style="width:200px">'+ demo +'</td>';
                        detailHtml += '<td class="c_blue txt_c" style="width:260px">'+ operateTime +'</td>';
                        detailHtml += '</tr>';
                    }
                    $("#showMsgDiv").html(detailHtml);
                }


            }
        });
    }

    function showDorMsgDetail(row){
        $.ajax({
            type : "post",
            url : "/archives/dormanyRecordList?id="+row,
            async : false,
            success : function(data){
                if (data.status != 0){
                    alert(data.msg);
                }else {
                    $("#msgDorShowModal").modal('show');
                    var list = [];
                    list = data.msglist;
                    listlength = list.length;
                    var detailHtml = '<tr><th style="width:200px;">原因</th><th style="width:260px;">时间</th></tr>';
                    for (var i = 0; i < list.length; i++) {
                        var demo = list[i].demo;
                        var operateTime = list[i].operateTime;
                        if(operateTime==""||operateTime==null||operateTime=="null"){
                            operateTime="-";
                        }
                        detailHtml += '<tr>';
                        detailHtml += '<td class="txt_c" style="width:200px">'+ demo +'</td>';
                        detailHtml += '<td class="c_blue txt_c" style="width:260px">'+ operateTime +'</td>';
                        detailHtml += '</tr>';
                    }
                    $("#dorHistoryDiv").html(detailHtml);
                }
            }
        });
    }

    function showWaitDorMsgDetail(row){
        $.ajax({
            type : "post",
            url : "/archives/waitDormanyRecordList?id="+row,
            async : false,
            success : function(data){
                if (data.status != 0){
                    alert(data.msg);
                }else {
                    $("#waitDorShowModal").modal('show');
                    var list = [];
                    list = data.msglist;
                    listlength = list.length;
                    var detailHtml = '<tr><th style="width:200px;">原因</th><th style="width:260px;">时间</th></tr>';
                    for (var i = 0; i < list.length; i++) {
                        var demo = list[i].demo;
                        var operateTime = list[i].operateTime;
                        if(operateTime==""||operateTime==null||operateTime=="null"){
                            operateTime="-";
                        }
                        detailHtml += '<tr>';
                        detailHtml += '<td class="txt_c" style="width:200px">'+ demo +'</td>';
                        detailHtml += '<td class="c_blue txt_c" style="width:260px">'+ operateTime +'</td>';
                        detailHtml += '</tr>';
                    }
                    $("#waitDorHistoryDiv").html(detailHtml);
                }
            }
        });
    }
</script>